<?php

namespace app\admin\controller;

use app\api\controller\ApiBaseController;
use app\common\attributes\Menu;
use app\common\service\OperatLogService;
use think\annotation\Inject;
use think\response\Json;

class OperatLogController extends AdminBaseController
{

    #[Inject]
    protected \app\common\model\OperatLog $model;


    #[Inject]
    protected OperatLogService $service;

    #[Menu('查看操作日志列表')]
    public function index() : Json
    {
        $data = $this->getParams();
        //当前是否为关联查询
        $this->relationSearch = true;
        //设置过滤方法
        $this->request->filter(['trim']);
        $extendQueryHelper = $this->buildParams();
        $list = $this->service->getOperatLogList($extendQueryHelper, $data);
        foreach ($list as $row) {
        }
        return $this->success($list);
    }

    #[Menu('查看操作日志详情')]
    public function read($operat_log_id) : Json
    {
        $res = $this->service->getOperatLogItem($operat_log_id);
        return $this->returnSuccess($res);
    }

    #[Menu('删除操作日志')]
    public function del($operat_log_id) : Json
    {
        $res = $this->service->delOperatLogItem($operat_log_id);
        return $this->returnSuccess($res);
    }

    #[Menu('更新操作日志')]
    public function update($operat_log_id) : \think\response\Json
    {
        $data = $this->getParams();
        $res = $this->service->setOperatLogItem($operat_log_id, $data);
        return $this->returnSuccess($res);
    }

    #[Menu('新增操作日志')]
    public function save() : Json
    {
        $data = $this->getParams();
        $res = $this->service->addOperatLogItem($data);
        return $this->returnSuccess($res);
    }

    #[Menu('清空操作日志')]
    public function clear() : Json
    {
        $res = $this->service->clear();
        return $this->returnSuccess($res);
    }

}
